package com.ruoyi.qiushi.service.mall.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.qiushi.domain.system.QiushiMessage;
import com.ruoyi.qiushi.domain.mall.TradePointOrder;
import com.ruoyi.qiushi.mapper.system.QiushiMessageMapper;
import com.ruoyi.qiushi.mapper.mall.TradePointOrderMapper;
import com.ruoyi.qiushi.service.mall.ITradePointOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 积分商品订单Service业务层处理
 *
 * @author ruoyi
 * @date 2023-12-27
 */
@Service
public class TradePointOrderServiceImpl implements ITradePointOrderService {
    @Autowired
    private TradePointOrderMapper tradePointOrderMapper;
    @Autowired
    private QiushiMessageMapper qiushiMessageMapper;

    /**
     * 查询积分商品订单
     *
     * @param id 积分商品订单主键
     * @return 积分商品订单
     */
    @Override
    public TradePointOrder selectTradePointOrderById(Long id) {
        return tradePointOrderMapper.selectTradePointOrderById(id);
    }

    /**
     * 查询积分商品订单列表
     *
     * @param tradePointOrder 积分商品订单
     * @return 积分商品订单
     */
    @Override
    public List<TradePointOrder> selectTradePointOrderList(TradePointOrder tradePointOrder) {
        return tradePointOrderMapper.selectTradePointOrderList(tradePointOrder);
    }

    /**
     * 新增积分商品订单
     *
     * @param tradePointOrder 积分商品订单
     * @return 结果
     */
    @Override
    public int insertTradePointOrder(TradePointOrder tradePointOrder) {
        tradePointOrder.setCreateTime(DateUtils.getNowDate());
        return tradePointOrderMapper.insertTradePointOrder(tradePointOrder);
    }

    /**
     * 修改积分商品订单
     *
     * @param tradePointOrder 积分商品订单
     * @return 结果
     */
    @Override
    public int updateTradePointOrder(TradePointOrder tradePointOrder) {
        tradePointOrder.setStatus("3");
        tradePointOrder.setDeliveryTime(new Date());
        tradePointOrder.setUpdateTime(DateUtils.getNowDate());

        QiushiMessage qiushiMessage = new QiushiMessage();
        qiushiMessage.setUserId(tradePointOrder.getUserId());
        qiushiMessage.setTitle("积分商品发货");
        qiushiMessage.setContent("积分商品订单“" + tradePointOrder.getId() + "”已发货，请及时确认收货");
        qiushiMessage.setType("1");
        qiushiMessage.setCreateTime(new Date());
        qiushiMessage.setUpdateTime(new Date());
        qiushiMessageMapper.insertQiushiMessage(qiushiMessage);

        return tradePointOrderMapper.updateTradePointOrder(tradePointOrder);
    }

    /**
     * 删除积分商品订单信息
     *
     * @param id 积分商品订单主键
     * @return 结果
     */
    @Override
    public int deleteTradePointOrderById(Long id) {
        return tradePointOrderMapper.deleteTradePointOrderById(id);
    }
}
